/*
 * @Author: lande 615542329@qq.com
 * @Date: 2023-02-15 14:05:22
 * @LastEditors: lande 615542329@qq.com
 * @LastEditTime: 2023-03-08 14:03:35
 * @FilePath: \ScriptProjects\DiyFunction\diy_module.js
 * @Description: diy_module
 * @version: 1
 */

const DiyModule = {};

/**
 * @description: 点击控件坐标
 * @param {Object} widget 控件对象
 * @return {Boolean} 控件不存在返回false，点击失败返回false，点击成功返回true
 */
DiyModule.clickWidget = function (widget) {
    try {
        if (!widget) {
            return false;
        }
        const x = random(widget.bounds().left + 1, widget.bounds().right - 1);
        const y = random(widget.bounds().top + 1, widget.bounds().bottom - 1);
        const time = random(150, 280);
        sleep(random(500, 1000));
        return press(x, y, time);
    } catch (error) {
        console.log('点击控件坐标报错：', error);
    }
    console.log("报错的控件：", widget);
    return false;

}

/**
 * @description: 点击控件
 * @param {Object} widget 控件对象
 * @return {Boolean} 控件不存在返回false，点击失败返回false，点击成功返回true
 */
DiyModule.clickWidgetEx = function (widget) {
    try {
        if (!widget) {
            return false;
        }
        sleep(random(500, 1000));
        return widget.click();
    } catch (error) {
        console.log('点击控件报错：', error);
    }
    return false;

}

/**
 * @description: sleep函数的增强函数
 * @param {Number} time1 时间1 这个参数不传，将默认使用500ms。
 * @param {Number} time2 时间2 这个参数不传，将默认使用time1的1.3倍数值。
 * @return {*} void 
 */
DiyModule.sleepEx = function (time1, time2) {
    try {
        time1 = typeof time1 == 'undefined' ? 500 : time1;
        time2 = typeof time2 == 'undefined' ? parseInt(time1 * 1.3) : time2;
        sleep(random(time1, time2));
    } catch (error) {
        console.log('延迟Ex报错: ', error);
    }
}

/**
 * @description: 判断控件是否处于安全边界内
 * @param {Object} widget 控件对象
 * @param {*} returnType 返回值类型，填object返回坐标对象{left:123,top:456,right:789,bottom:012},控件不在安全边界或不填返回Boolean类型的值，
 * @return {Boolean} Boolean
 */
DiyModule.widgetBounds = function (widget, returnType) {
    try {
        if (!widget) {
            return false;
        }
        const bool = widget.bounds().left < widget.bounds().right && widget.bounds().left >= 0 && widget.bounds().top < widget.bounds().bottom && widget.bounds().top >= 0;
        if (bool && returnType == 'object') {
            return {
                left: widget.bounds().left,
                top: widget.bounds().top,
                right: widget.bounds().right,
                bottom: widget.bounds().bottom
            };
        }
        return bool;

    } catch (error) {
        console.log('控件安全边界报错: ', error);
    }
    return false;
}


/**
 * @description: 仿真随机带曲线滑动, qx, qy, zx, zy, time 代表起点x,起点y,终点x,终点y,过程耗时单位毫秒
 * @param {Number} qx
 * @param {Number} qy
 * @param {Number} zx
 * @param {Number} zy
 * @param {Number} time
 * @return {*}
 */
DiyModule.sml_move = function (qx, qy, zx, zy, time) {

    /**
    * @description: 随机曲线算法
    * @param {ArrayList} cp 这是一个数组,用来传入位置参数
    * @param {Number} t 时间
    * @return {*}
    */
    function bezier_curves(cp, t) {
        cx = 3.0 * (cp[1].x - cp[0].x);
        bx = 3.0 * (cp[2].x - cp[1].x) - cx;
        ax = cp[3].x - cp[0].x - cx - bx;
        cy = 3.0 * (cp[1].y - cp[0].y);
        by = 3.0 * (cp[2].y - cp[1].y) - cy;
        ay = cp[3].y - cp[0].y - cy - by;

        tSquared = t * t;
        tCubed = tSquared * t;
        result = {
            "x": 0,
            "y": 0
        }
        result.x = (ax * tCubed) + (bx * tSquared) + (cx * t) + cp[0].x;
        result.y = (ay * tCubed) + (by * tSquared) + (cy * t) + cp[0].y;
        return result;
    }

    var xxy = [time];
    var point = [];
    var dx0 = {
        "x": qx,
        "y": qy
    }

    var dx1 = {
        "x": random(qx - 100, qx + 100),
        "y": random(qy, qy + 50)
    }

    var dx2 = {
        "x": random(zx - 100, zx + 100),
        "y": random(zy, zy + 50),
    }
    var dx3 = {
        "x": zx,
        "y": zy
    }
    for (var i = 0; i < 4; i++) {

        eval("point.push(dx" + i + ")");

    }
    // log(point[3].x)

    for (let i = 0; i < 1; i += 0.08) {
        xxyy = [parseInt(bezier_curves(point, i).x), parseInt(bezier_curves(point, i).y)]

        xxy.push(xxyy);

    }

    // log(xxy);
    gesture.apply(null, xxy);

}


/**
 * @description: 仿真随机带曲线滑动 (梦境加强版)
 * @param {*}
 * @return {*}
 */
DiyModule.smlMoveUp = function () {
    let rndNum = random(1, 5);
    let dw = device.width;
    let dh = device.height;
    switch (rndNum) {
        case 1:
            DiyModule.sml_move(parseInt(dw * 0.42), parseInt(dh * 0.82), parseInt(dw * 0.36), parseInt(dh * 0.18), 1206);
            break;
        case 2:
            DiyModule.sml_move(parseInt(dw * 0.55), parseInt(dh * 0.75), parseInt(dw * 0.83), parseInt(dh * 0.15), 1170);
            break;
        case 3:
            DiyModule.sml_move(parseInt(dw * 0.76), parseInt(dh * 0.7), parseInt(dw * 0.9), parseInt(dh * 0.18), 926);
            break;
        case 4:
            DiyModule.sml_move(parseInt(dw * 0.69), parseInt(dh * 0.73), parseInt(dw * 0.42), parseInt(dh * 0.16), 807);
            break;
        case 5:
            DiyModule.sml_move(parseInt(dw * 0.48), parseInt(dh * 0.76), parseInt(dw * 0.69), parseInt(dh * 0.15), 1305);
            break;
    }
}

/**
 * @description: 获取当前控件的指定同级控件
 * @param {Object} widget 当前控件
 * @param {Number} index 指定的第几个子控件，从0开始计算。
 * @return {Object} 返回 指定的同级控件
 */
DiyModule.getLevel = function (widget, index) {
    try {
        let parentWidget = widget && widget.parent();
        let childCount = parentWidget && parentWidget.childCount();
        return childCount > index ? parentWidget.child(index) : null;

    } catch (error) {
        log("获取当前控件的同级控件报错:", error);
    }
}

/**
 * @description: 传入控件对象的参数，查找控件，并返回控件
 * @param {Object} object 控件对象属性，例：{text:"hello"}
 * @param {String} type 传入 t,i,c,tc,ti,tic其中一个字符串，代表使用的查找方式。
 * @return {Object} Object
 */
DiyModule.findWidget = function (object, type) {
    try {
        // console.log("type:", type);
        type = type == "ct" ? "tc" : type;
        type = type == "it" ? "ti" : type;
        type = type == "ci" ? "ic" : type;
        type = type.indexOf("t") > -1 && type.indexOf("i") > -1 && type.indexOf("t") > -1 ? "tic" : type;
        switch (type) {
            case "t":
                return text(object.text).findOnce() || desc(object.text).findOnce();
            case "i":
                return id(object.id).findOnce();
            case "c":
                return className(object.className).findOnce();
            case "tc":
                return text(object.text).className(object.className).findOnce() || desc(object.text).className(object.className).findOnce();
            case "ti":
                return text(object.text).id(object.id).findOnce() || desc(object.text).id(object.id).findOnce();
            case "tic":
                return text(object.text).id(object.id).className(object.className).findOnce() || desc(object.text).id(object.id).className(object.className).findOnce();
            case "ic":
                return id(object.id).className(object.className).findOnce();
        }
    } catch (error) {
        console.log("查找控件报错: ", error);
    }
    return null;
}

/**
 * @description: 关闭指定包名的软件
 * @param {String} packageName1
 * @return {*} void
 */
DiyModule.closeApp = function (packageName1) {
    $app.openAppSetting(packageName1);
    sleep(2000);
    let time1 = new Date();
    while (!DiyModule.findWidget({ text: $app.getAppName(packageName1), id: "android:id/title", className: "android.widget.TextView" }, "tic")) {
        let time2 = new Date();
        let time3 = (time2 - time1) / 1000;
        if (time3 > 15) {
            back();
            sleep(1000);
            home();
            sleep(2000);
            time1 = new Date();
            $app.openAppSetting(packageName1);
        }
        sleep(3000);
    }

    while (!text("FORCE STOP").id("com.android.settings:id/right_button").className("android.widget.Button").enabled(false).findOnce()) {
        DiyModule.clickWidget(text("FORCE STOP").id("com.android.settings:id/right_button").className("android.widget.Button").enabled(true).findOnce());
        DiyModule.clickWidget(DiyModule.findWidget({ text: "OK", id: "android:id/button1", className: "android.widget.Button" }, "tic"));
    }
    back();
    sleep(1000);
    home();
    sleep(2000);

}


/**
 * @description: 关闭指定包名的软件
 * @param {String} packageName1
 * @return {*} void
 */
DiyModule.clearApp = function (packageName1) {
    $app.openAppSetting(packageName1);
    sleep(2000);
    let time1 = new Date();
    while (!DiyModule.findWidget({ text: $app.getAppName(packageName1), id: "android:id/title", className: "android.widget.TextView" }, "tic")) {
        let time2 = new Date();
        let time3 = (time2 - time1) / 1000;
        if (time3 > 15) {
            back();
            sleep(1000);
            home();
            sleep(2000);
            time1 = new Date();
            $app.openAppSetting(packageName1);
        }
        sleep(3000);
    }

    while (!text("CLEAR DATA").id("com.android.settings:id/button").className("android.widget.Button").enabled(false).findOnce()) {
        DiyModule.clickWidget(DiyModule.findWidget({ text: "Storage", id: "android:id/title", className: "android.widget.TextView" }, "tic"));
        DiyModule.clickWidget(text("CLEAR DATA").id("com.android.settings:id/button").className("android.widget.Button").enabled(true).findOnce());
        DiyModule.clickWidget(DiyModule.findWidget({ text: "OK", id: "android:id/button1", className: "android.widget.Button" }, "tic"));
    }
    back();
    sleep(1000);
    home();
    sleep(2000);

}

/**
 * @description: 修改vpn
 * @return {*}
 */
DiyModule.changeVpn = function () {
    function VpnClassEx() {
        this.status = "getVpnLink";
        this.control = true;
        this.vpnLink = "";
        /**
         * @description: 获取vpn链接
         * @return {*}
         */
        this.getVpnLink = function () {
            try {
                let storage = storages.create("biyun");
                // storage.put("vpnlink", "trojan://ruichi123456@tsgg1.cloudscapeing.com:10252?type=tcp&security=tls&headerType=none#%E8%87%82%E4%BA%91-%E8%85%BE%E8%AE%AF%E4%BA%91-%E7%A1%85%E8%B0%B7-2");
                this.vpnLink = storage.get("vpnlink");
                console.log("vpnlink: ", this.vpnLink);
                this.status = "launchV2ray";
                return this.vpnLink;
            } catch (error) {
                console.log("获取vpn链接报错: ", error);
            }
            return null;

        }
        /**
         * @description: 启动v2ray
         * @return {*}
         */
        this.launchV2ray = function () {
            $app.launch('com.v2ray.ang');
            DiyModule.sleepEx(2000);
            let time1 = new Date();
            while (!packageName('com.v2ray.ang').findOnce()) {

                let time2 = new Date();
                let time3 = parseInt(time2 - time1) / 1000;
                if (time3 > 30) {
                    $app.launch('com.v2ray.ang');
                }
            }
            this.status = "stopV2ray";

        }
        /**
         * @description: 停止当前运行的v2ray
         * @return {*}
         */
        this.stopV2ray = function () {
            if (DiyModule.findWidget({ text: "Not connected", id: "com.v2ray.ang:id/tv_test_state", className: "android.widget.TextView" }, "tic")) {
                this.status = "setV2ray";

            } else if (DiyModule.findWidget({ text: "Connected, tap to check connection", id: "com.v2ray.ang:id/tv_test_state" }, "ti") || textContains("Success: HTTP connection took").findOnce()) {
                this.status = "finish";
            } else {
                DiyModule.closeApp('com.v2ray.ang');
                DiyModule.sleepEx(2000);
                this.launchV2ray();
                this.stopV2ray();
            }

        }

        /**
         * @description: 设置v2ray
         * @return {*}
         */
        this.setV2ray = function () {
            // console.log("开始-setV2ray");
            let obj = DiyModule.findWidget({ id: "com.v2ray.ang:id/filter_config", className: "android.widget.TextView" }, "ic");
            console.log(obj);
            DiyModule.clickWidget(DiyModule.getLevel(obj, 2));
            DiyModule.clickWidget(DiyModule.findWidget({ text: "Delete all config", id: "com.v2ray.ang:id/title", className: "android.widget.TextView" }, "tic"));
            if (DiyModule.clickWidget(DiyModule.findWidget({ text: "OK", id: "android:id/button1", className: "android.widget.Button" }, "tic"))) {
                DiyModule.sleepEx(2000);
                //     DiyModule.clickWidget(DiyModule.findWidget({ text: "Type manually[Trojan]", id: "com.v2ray.ang:id/title", className: "android.widget.TextView" }, "tic"));
                //     let remarks = DiyModule.findWidget({ id: "com.v2ray.ang:id/et_remarks", className: "android.widget.EditText" }, "ic");
                //     if (remarks) {
                //         remarks.setText(this.vpnUser);
                //         DiyModule.sleepEx(1000);
                //     }

                //     let address = DiyModule.findWidget({ id: "com.v2ray.ang:id/et_address", className: "android.widget.EditText" }, "ic");
                //     if (remarks) {
                //         remarks.setText(this.address);
                //         DiyModule.sleepEx(1000);
                //     }

                //     let port = DiyModule.findWidget({ id: "com.v2ray.ang:id/et_port", className: "com.v2ray.ang:id/et_port" }, "ic");
                //     if (port) {
                //         port.setText(this.port);
                //         DiyModule.sleepEx(1000);

                //     }

                //     let passWord = DiyModule.findWidget({ id: "com.v2ray.ang:id/et_id", className: "android.widget.EditText" }, "ic");
                //     if (passWord) {
                //         passWord.setText(this.password);
                //         DiyModule.sleepEx(1000);

                //         // 点击完成
                //         DiyModule.clickWidget(DiyModule.findWidget({ id: "com.v2ray.ang:id/save_config", className: "android.widget.TextView" }, "ic"));
                //     }
                console.log("设置剪贴板");
                // 设置剪贴板
                setClip(this.vpnLink);
                DiyModule.sleepEx(1000);
                console.log("剪贴板内容：", getClip());
                DiyModule.clickWidget(DiyModule.getLevel(DiyModule.findWidget({ id: "com.v2ray.ang:id/filter_config", className: "android.widget.TextView" }, "ic"), 0)) && DiyModule.sleepEx(1500);
                DiyModule.clickWidget(DiyModule.findWidget({ text: "Import config from Clipboard", id: "com.v2ray.ang:id/title", className: "android.widget.TextView" }, "tic")) && DiyModule.sleepEx(1500);
                if (DiyModule.findWidget({ id: "com.v2ray.ang:id/tv_statistics", className: "android.widget.TextView" }, "ic")) {
                    DiyModule.clickWidget(DiyModule.findWidget({ id: "com.v2ray.ang:id/fab", className: "android.widget.ImageButton" }, "ic")) && DiyModule.sleepEx(2000);
                    let count = 0;
                    let time1 = new Date();
                    while (!textContains("Success: HTTP connection took").id("com.v2ray.ang:id/tv_test_state").className("android.widget.TextView").findOnce()) {
                        DiyModule.clickWidget(DiyModule.findWidget({ text: "Connected, tap to check connection", id: "com.v2ray.ang:id/tv_test_state", className: "android.widget.TextView" }, "tic"));
                        let time2 = new Date();
                        let time3 = parseInt(time2 - time1) / 1000;
                        if (time3 > 30) {
                            count++;
                            if (count > 2) {
                                break;
                            }
                            time1 = new Date();
                            // 关闭当前连接的v2
                            DiyModule.clickWidget(DiyModule.findWidget({ id: "com.v2ray.ang:id/fab", className: "android.widget.ImageButton" }, "ic")) && DiyModule.sleepEx(2000);
                            // 进行递归
                            this.setV2ray();
                        }
                    }
                    this.status = "finish";

                }

            }
        }

        /**
         * @description: v2ray设置主函数
         * @return {*}
         */
        this.main = function () {

            while (this.control) {
                console.log("this.status: ", this.status);
                switch (this.status) {
                    case "getVpnLink":
                        this.getVpnLink();
                        break;

                    case "launchV2ray":
                        this.launchV2ray();
                        break;
                    case "stopV2ray":
                        this.stopV2ray();
                        break;
                    case "setV2ray":
                        this.setV2ray();
                        break;
                    case "finish":
                        home();
                        DiyModule.sleepEx(2000);
                        console.log("完成-v2ray设置");
                        return;
                }

                sleep(100);
            }

        }
    }
    const Vpn = new VpnClassEx();
    Vpn.main();
}


/**
 * @description: 结束自身进程
 * @return {*}
 */
DiyModule.processOver = function () {
    let nowPid = android.os.Process.myPid();
    let am = context.getSystemService(java.lang.Class.forName("android.app.ActivityManager"));
    let list = am.getRunningAppProcesses();
    for (let i = 0; i < list.size(); i++) {
        let info = list.get(i);
        if (info.pid != nowPid) {
            kill(info.pid);
        }
    }
    kill(nowPid);
    java.lang.System.exit(0);
    function kill(pid) {
        android.os.Process.killProcess(pid);
    }
}

/**
* @description: 拼接get字符串
* @param {Object} paramObj 传入一个参数对象
* @return {string} 返回一个拼接好的字符串
*/
DiyModule.contactParam = function (paramObj) {
    let endStr = "";
    let count = 1;
    for (let key in paramObj) {
        log("key=" + key);
        if (Object.hasOwnProperty.call(paramObj, key)) {
            let element = paramObj[key];
            if (count == 1) {
                endStr = "?" + key + "=" + element;
                count++;
            } else {
                endStr = endStr + "&" + key + "=" + element;
            }

        }
    }

    return endStr;
}
/**
 * @description: 请求服务端类
 * @param {String} optBaseUrl 基础url
 * @param {String} accessKey 请求头的权限验证
 * @param {Number} detailId 任务id WSTaskParam.data.detailId
 * @return {*}
 */
DiyModule.ClassRequest = function (optBaseUrl, accessKey, detailId) {
    this.optBaseUrl = optBaseUrl;
    this.accessKey = accessKey;
    this.detailId = detailId;
    /**
     * @description: 更换手机号码
     * @param {String} phoneNumber 旧的手机号码 WSTaskParam.data.phoneNumber
     * @return {String} String 获取成功返回手机号，失败返回null
     */
    this.changePhoenNum = function (phoneNumber) {
        try {
            let obj = {
                phoneNumber: phoneNumber,
                detailId: this.detailId
            }
            let param = DiyModule.contactParam(obj);
            let res = http.get(this.optBaseUrl + "/overseas/composite/sms/changePhone" + param, {
                headers: {
                    "access-key": this.accessKey
                }
            });
            let retJson = res.body.json();
            if (retJson.code == 200) {
                if (retJson.data.length > 5) {
                    return retJson.data;
                }
                return null;
            }
        } catch (error) {
            console.log("更换电话号码报错：", error);
        }
        return null;
    }

    /**
     * @description: 获取手机验证码
     * @param {String} phoneNumber 手机号码
     * @param {String} waitTime 最大等待时间(单位ms)，0为立即返回，必须为10的倍数
     * @return {String} String 成功返回验证码，失败返回null
     */
    this.getOpt = function (phoneNumber, waitTime) {
        try {
            let obj = {
                phoneNumber: phoneNumber,
                detailId: this.detailId,
                waitTime: waitTime
            }
            let param = DiyModule.contactParam(obj);
            let res = http.get(this.optBaseUrl + "/overseas/composite/sms/getCode" + param, {
                headers: {
                    "access-key": this.accessKey
                }
            });
            let retJson = res.body.json();
            if (retJson.code == 200) {
                if (retJson.data.length > 5) {
                    return retJson.data;
                }
                return null;
            }
        } catch (error) {
            console.log("获取验证码报错：", error);
        }
        return null;
    }

    /**
     * @description: 完成任务
     * @param {String} remark 任务结果说明
     * @param {Number} status 2-成功 ，3-失败
     * @return {Boolean} Boolean 成功返回true，失败返回false
     */
    this.finishTask = function (remark, status) {
        try {
            let obj = {
                remark: remark,
                detailId: this.detailId,
                status: status
            }
            console.log("最后上报obj: ", obj);
            let param = DiyModule.contactParam(obj);
            let res = http.get(this.optBaseUrl + "/overseas/composite/task/finishTask" + param, {
                headers: {
                    "access-key": this.accessKey
                }
            });
            let retJson = res.body.json();
            if (retJson.code == 200) {
                return true;
            }

        } catch (error) {
            console.log("上报完成任务报错：", error);
        }
        return false;
    }

    /**
     * @description: WhatsApp提交单条消息的发送结果
     * @param {String} key 消息的标识 whatsApp是好友联系人的phone
     * @param {Number} status 2-成功 ，3-失败
     * @return {Boolean} Boolean 成功返回true，失败返回false
     */
    this.reportSendResult = function (key, status) {
        try {
            let sendUrl = this.optBaseUrl + "/overseas/composite/mass/reportSendResult"
            let obj = {
                key: key,
                detailId: this.detailId,
                status: status
            }
            console.log("单条obj: ", obj);
            let res = http.postJson(sendUrl, obj, {
                headers: {
                    "access-key": this.accessKey
                }
            });
            let retJson = res.body.json();
            if (retJson.code == 200) {
                return true;
            }
        } catch (error) {
            console.log("单条消息的发送结果-报错：", error);
        }
        return false;
    }
}

/**
 * @description: 返回国家完整名字
 * @param {String} abbreviatedName 简写名字
 * @param {String} language 返回的语言类型，不写/0：英语，1：中文
 * @return {String} String 
 */
DiyModule.countryNameAll = function (abbreviatedName, language) {
    try {
        language = language == undefined ? 0 : language;
        switch (abbreviatedName) {
            case "us":
                return language == 0 ? "United States" : "美国";
            case "id":
                return language == 0 ? "Indonesia" : "印度尼西亚";
            case "in":
                return language == 0 ? "India" : "印度";
            case "sa":
                return language == 0 ? "Saudi Arabia" : "沙特阿拉伯";
            case "th":
                return language == 0 ? "Thailand" : "泰国";
            case "ph":
                return language == 0 ? "Philippines" : "菲律宾";
            case "ke":
                return language == 0 ? "Kenya" : "肯尼亚";
        }
    } catch (error) {
        console.log("返回国家全名报错：", error);
    }
    return null;
}

/**
 * @description: 手机参数类
 * @return {*}
 */
DiyModule.PhoneParam = function () {
    /**
    * @description: 修改手机参数
    * @param {*} paramObj 从后台获取的参数json表
    * @return {*} 
    */
    this.main = function (object) {
        console.log(object);
        // let object = JSON.parse(paramObj);
        for (let key in object) {
            if (Object.hasOwnProperty.call(object, key)) {
                let element = object[key];
                this.setParam(key, element);
            }
        }
        console.log("完成-设置手机参数");
    }

    /**
     * @description: 设置指定手机参数
     * @param {String} key 待设置的手机参数
     * @param {String} value 手机参数值
     * @return {object} object 返回对象 
     */
    this.setParam = function (key, value) {
        console.log(typeof key, typeof value);
        console.log(key, value);
        let shellValue = "setprop " + key + " '" + value + "'";
        console.log("shellValue: ", shellValue);
        let result = shell(shellValue, true);
        console.log(result);
        // ShellResult{code=0, error='', result=''}  --成功
        // ShellResult{code=1, error='sh: <stdin>[1]: syntax error: '(' unexpected', result=''}  --失败
        return result;
    }

    /**
     * @description: 获取指定手机参数的值
     * @param {String} key 手机参数
     * @return {object} object 返回对象
     */
    this.getParam = function (key) {
        // ShellResult{code=0, error='', result='186(C00)R2'}
        return shell("getprop " + key, true);
    }
}


/**
 * @description: 是否已经修改了vpn
 * @param {String} country 国家名-中文
 * @return {Boolean} Boolean true:已修改，不需要修改，false：未修改，需要修改。
 */
DiyModule.isChangeVpn = function (country) {
    try {
        let res = http.get("http://cip.cc");
        if (res.statusCode == 200) {
            let retData = res.body.string();
            // console.log(retData);
            let startPoint = retData.indexOf("数据二	:");
            let endPoint = retData.indexOf("数据三");
            let str01 = retData.slice(startPoint + "数据二	:".length, endPoint);
            let ipCountry = str01.trim();
            console.log(ipCountry);
            return ipCountry.indexOf(country) > -1 ? true : false;
        }

    } catch (error) {
        console.log("判断ip国家报错: ", error);
    }

    return false;
}


/**
 * @description: 获取资源ID
 * @return {*}
 */
DiyModule.getResourceId = function () {
    try {
        let res = http.get("http://localhost:9898/gosea/deviceResourceId");
        if (res.statusCode == 20) {
            return res.body.json().data.deviceResourceId;
        }

    } catch (error) {
        console.log("报错-获取资源ID: ", error);
    }
}

/**
 * @description: 输入法开关
 * @param {*} enableValue 0：打开输入法，1：关闭输入法
 * @return {*}
 */
DiyModule.switchInput = function (enableValue) {
    try {
        let res = http.post("http://localhost:9898/enable/input", {
            "enable": enableValue
        });
        if (res.body.json().code == 200) {
            return true;
        }
        return false;
    } catch (error) {
        console.log("报错-开关输入法报错: ", error);
    }
}

/**
 * @description: 设置日志
 * @param {String} platform 平台
 * @return {*}
 */
DiyModule.setGlobalLog = function (platform) {
    try {
        let pathLog = "/sdcard/biyun_log/" + platform + "/log.txt";
        if (files.exists(pathLog)) {
            files.remove(pathLog);
        }
        files.ensureDir(pathLog);
        files.createWithDirs(pathLog);
        console.setGlobalLogConfig({
            "file": pathLog,
            "maxFileSize": 10 * 1024 * 1024
        });
    } catch (error) {
        console.log("设置日志报错: ", error);
    }
}


/**
 * @description: 后端已经写了
 * @return {*}
 */
DiyModule.ClassPhoneCode = {
    username: null,
    password: null,
    token: null,
    phone: null,
    apikey: null,
    type: null,
    /**
     * @description: 登录平台
     * @return {*}
     */
    login: function () {

    },
    /**
     * @description: 获取手机号码
     * @return {*}
     */
    getPhone: function () {

    },
    /**
     * @description: 获取验证码
     * @return {*}
     */
    getCode: function () {

    },
    /**
     * @description: 释放手机号
     * @return {*}
     */
    releasePhone: function () {

    },
    /**
     * @description: 拉黑手机号
     * @return {*}
     */
    blockPhone: function () {

    }
}

/**
 * @description: 后端已经写了
 * @param {*} username
 * @param {*} password
 * @param {*} apiNmae
 * @return {*}
 */
DiyModule.HuoHuLi = function (username, password, apiNmae) {
    this.username = username;
    this.password = password;
    this.apiName = apiNmae;
    this.login = function () {

    }
}

module.exports = DiyModule;